package com.minotauro.i18n.base;

import java.util.List;
import java.util.Locale;

import org.apache.commons.lang.SystemUtils;

import com.minotauro.bean.property.PropertyBean;
import com.minotauro.cleda.util.CledaLocaleUtils;
import com.minotauro.i18n.base.CodeGenerator.Mode;

public class BaseI18NMain {

  public static final String DEFAULT_LANGUAGE/**/= "en";
  public static final String DEFAULT_COUNTRY/* */= "US";
  public static final String DEFAULT_VARIANT/* */= null;

  // ---------------------------------------------------------------------------------------------------------------------------

  public BaseI18NMain() {
    // Empty
  }

  // ---------------------------------------------------------------------------------------------------------------------------

  protected String getBasePathInput(String input, String packg) {
    StringBuffer ret = new StringBuffer();
    ret.append(SystemUtils.USER_DIR);
    ret.append(SystemUtils.FILE_SEPARATOR);
    ret.append(input.replace("/", SystemUtils.FILE_SEPARATOR));
    ret.append(packg.replace(".", SystemUtils.FILE_SEPARATOR));
    return ret.toString();
  }

  // ---------------------------------------------------------------------------------------------------------------------------

  protected String getBasePathOutput(String output, String packg) {
    StringBuffer ret = new StringBuffer();
    ret.append(SystemUtils.USER_DIR);
    ret.append(SystemUtils.FILE_SEPARATOR);
    ret.append(output.replace("/", SystemUtils.FILE_SEPARATOR));
    ret.append(packg.replace(".", SystemUtils.FILE_SEPARATOR));
    return ret.toString();
  }

  // ---------------------------------------------------------------------------------------------------------------------------

  public void prop(List<PropertyBean> propertyBeanList, String className,
      String output, String packg) throws Exception {
    com.minotauro.bean.property.CodeGenerator codeGenerator;

    codeGenerator = new com.minotauro.bean.property.CodeGenerator( //
        propertyBeanList, className, getBasePathOutput(output, packg), packg);
    codeGenerator.run();

  }

  // ---------------------------------------------------------------------------------------------------------------------------

  public void i18n(String name, String language, String country,
      String variant, String input, String output, String packg)
      throws Exception {
    i18n(name, CledaLocaleUtils.createLocale(language, country, variant),
        input, output, packg);
  }

  public void i18n(String name, Locale locale, String input, String output,
      String packg) throws Exception {
    CodeGenerator codeGenerator = new CodeGenerator( //
        locale, //
        getBasePathInput(input, packg), name, getBasePathOutput(output, packg), //
        packg, //
        MessageBase.class.getName(), Mode.I18N);
    codeGenerator.run();
  }

  public void i18n(String name, String input, String output, String packg)
      throws Exception {
    i18n(name, DEFAULT_LANGUAGE, DEFAULT_COUNTRY, DEFAULT_VARIANT, input,
        output, packg);
  }

  // ---------------------------------------------------------------------------------------------------------------------------

  public void numb(String name, String language, String country,
      String variant, String input, String output, String packg)
      throws Exception {
    numb(name, CledaLocaleUtils.createLocale(language, country, variant),
        input, output, packg);
  }

  public void numb(String name, Locale locale, String input, String output,
      String packg) throws Exception {
    CodeGenerator codeGenerator = new CodeGenerator( //
        locale, //
        getBasePathInput(input, packg), name, getBasePathOutput(output, packg), //
        packg, //
        MessageBase.class.getName(), Mode.NUMB);
    codeGenerator.run();
  }

  public void numb(String name, String input, String output, String packg)
      throws Exception {
    numb(name, DEFAULT_LANGUAGE, DEFAULT_COUNTRY, DEFAULT_VARIANT, input,
        output, packg);
  }

  // ---------------------------------------------------------------------------------------------------------------------------

  public void date(String name, String language, String country,
      String variant, String input, String output, String packg)
      throws Exception {
    date(name, CledaLocaleUtils.createLocale(language, country, variant),
        input, output, packg);
  }

  public void date(String name, Locale locale, String input, String output,
      String packg) throws Exception {
    CodeGenerator codeGenerator = new CodeGenerator( //
        locale, //
        getBasePathInput(input, packg), name, getBasePathOutput(output, packg), //
        packg, //
        MessageBase.class.getName(), Mode.DATE);
    codeGenerator.run();
  }

  public void date(String name, String input, String output, String packg)
      throws Exception {
    date(name, DEFAULT_LANGUAGE, DEFAULT_COUNTRY, DEFAULT_VARIANT, input,
        output, packg);
  }

  // ---------------------------------------------------------------------------------------------------------------------------
}